package com.fancy.learncenter.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.PersonInfoActivity;
import com.fancy.learncenter.activity.ToothDetailsActivity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.WDListDataBean;
import com.superservice.lya.R;

import java.util.ArrayList;

/**
 * Created by hyy on 2018/1/27.
 * Explain activity as
 */

public class ToothWDAdapter extends CommonRecycleViewAdapter<WDListDataBean> {

    public ToothWDAdapter(Context mContext, ArrayList<WDListDataBean> itemDatas) {
        super(mContext, R.layout.fragment_tooth_wd_item, itemDatas);
    }

    boolean isMy = false;

    public ToothWDAdapter(Context mContext, ArrayList<WDListDataBean> itemDatas, boolean isMy) {
        super(mContext, R.layout.fragment_tooth_wd_item, itemDatas);
        this.isMy = isMy;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final WDListDataBean item, final int position) {

        SimpleDraweeView user_icon = customViewHold.getView(R.id.user_icon);
        user_icon.setImageURI(item.getImgsrc());
        user_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, PersonInfoActivity.class);
                intent.putExtra("userId", "" + item.getUser_id());
                mContext.startActivity(intent);
            }
        });


        TextView userName = customViewHold.getView(R.id.userName);
        userName.setText(item.getNick_name());

        TextView qustion = customViewHold.getView(R.id.qustion);
        qustion.setText(item.getTitle());

        TextView question_num = customViewHold.getView(R.id.question_num);
        question_num.setText(item.getComment_num() + "人回答");

        TextView time = customViewHold.getView(R.id.time);
        time.setText(item.getAdd_time() + "发布");

        TextView flag1 = customViewHold.getView(R.id.flag1);

        TextView islove = customViewHold.getView(R.id.islove);

        ImageView delete_img = customViewHold.getView(R.id.delete_img);
        if (isMy) {
            delete_img.setVisibility(View.VISIBLE);
            delete_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (deleteCallBack != null) {
                        deleteCallBack.deleteCallBack(position, item.getId());
                    }
                }
            });
        } else {
            delete_img.setVisibility(View.GONE);
        }
        SimpleDraweeView answer_icon = customViewHold.getView(R.id.answer_icon);
        if (item.getIs_solve().equals("1")) {
            flag1.setText("已解决");
            islove.setVisibility(View.VISIBLE);
            islove.setText(item.getSolve().getContent());

            answer_icon.setVisibility(View.VISIBLE);
            answer_icon.setImageURI(item.getSolve().getComment_user_img());


            customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, ToothDetailsActivity.class);
                    intent.putExtra("wdListDataBean", item.getId());
                    intent.putExtra("solve_id", item.getSolve().getId());
                    mContext.startActivity(intent);
                }
            });
        } else {
            flag1.setText("问.未解决");
            islove.setVisibility(View.GONE);

            answer_icon.setVisibility(View.GONE);

            customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, ToothDetailsActivity.class);
                    intent.putExtra("wdListDataBean", item.getId());
                    mContext.startActivity(intent);
                }
            });
        }

    }

    public DeleteCallBack getDeleteCallBack() {
        return deleteCallBack;
    }

    public void setDeleteCallBack(DeleteCallBack deleteCallBack) {
        this.deleteCallBack = deleteCallBack;
    }

    private DeleteCallBack deleteCallBack;

    public interface DeleteCallBack {
        abstract void deleteCallBack(int position, String caseId);
    }
}
